<?php

App::uses('SiteController', 'Controller');

class PetsController extends SiteController {
	
	public $name = 'Pets';
	
	public $uses = array('Pet');
	
	public function index() {
		$this->Pet->recursive = 0;
		$this->paginate = array (
			'order' => array('Pet.id' => 'desc')
		);
		$pets = $this->paginate('Pet');
		$this->set('pets', $pets);
	}
	
	public function create() {
		
		if( $this->request->is('post') ) {
			$this->Pet->create();
			if( $this->Pet->save($this->request->data) ) {
				$this->Session->setFlash('Pet created.');
				$this->redirect( array('action' => 'index') );
			}
			else {
				$this->Session->setFlash('Pet couldn\'t be created.');
				$this->log('Error saving Pet:');
				$this->log($this->Pet->validationErrors);
			}
		}
		
	}
	
}